package es.udc.emarketapp.http.view.actionForms;

import es.udc.fbellas.j2ee.util.struts.action.DefaultActionForm;
import es.udc.fbellas.j2ee.util.struts.action.PropertyValidator;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

public class ShippingForm extends DefaultActionForm {

    private String idSeller;
    private String idCountry;
    private String price1;
    private double price1AsDouble;
    private String price2;
    private double price2AsDouble;
    private String price3;
    private double price3AsDouble;
    private String price4;
    private double price4AsDouble;
    private String price5;
    private double price5AsDouble;
    private double range1;
    private double range2;
    private double range3;
    private double range4;
    private double range5;

    public ShippingForm() {
        reset();
    }

    public String getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(String idCountry) {
        this.idCountry = idCountry;
    }

    public String getIdSeller() {
        return idSeller;
    }

    public void setIdSeller(String idSeller) {
        this.idSeller = idSeller;
    }

    public String getPrice1() {
        return price1;
    }

    public void setPrice1(String price1) {
        this.price1 = price1;
    }

    public double getPrice1AsDouble() {
        return price1AsDouble;
    }

    public void setPrice1AsDouble(double price1AsDouble) {
        this.price1AsDouble = price1AsDouble;
    }

    public String getPrice2() {
        return price2;
    }

    public void setPrice2(String price2) {
        this.price2 = price2;
    }

    public double getPrice2AsDouble() {
        return price2AsDouble;
    }

    public void setPrice2AsDouble(double price2AsDouble) {
        this.price2AsDouble = price2AsDouble;
    }

    public String getPrice3() {
        return price3;
    }

    public void setPrice3(String price3) {
        this.price3 = price3;
    }

    public double getPrice3AsDouble() {
        return price3AsDouble;
    }

    public void setPrice3AsDouble(double price3AsDouble) {
        this.price3AsDouble = price3AsDouble;
    }

    public String getPrice4() {
        return price4;
    }

    public void setPrice4(String price4) {
        this.price4 = price4;
    }

    public double getPrice4AsDouble() {
        return price4AsDouble;
    }

    public void setPrice4AsDouble(double price4AsDouble) {
        this.price4AsDouble = price4AsDouble;
    }

    public String getPrice5() {
        return price5;
    }

    public void setPrice5(String price5) {
        this.price5 = price5;
    }

    public double getPrice5AsDouble() {
        return price5AsDouble;
    }

    public void setPrice5AsDouble(double price5AsDouble) {
        this.price5AsDouble = price5AsDouble;
    }

    public double getRange1() {
        return range1;
    }

    public double getRange2() {
        return range2;
    }

    public double getRange3() {
        return range3;
    }

    public double getRange4() {
        return range4;
    }

    public double getRange5() {
        return range5;
    }

    public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();
        PropertyValidator.validateMandatory(errors, "idSeller", idSeller);
        price1AsDouble = PropertyValidator.validateDouble(errors, "price1",
                price1, true, 0.01, 1000, getLocale(request));
        price2AsDouble = PropertyValidator.validateDouble(errors, "price2",
                price2, true, 0.01, 1000, getLocale(request));
        price3AsDouble = PropertyValidator.validateDouble(errors, "price3",
                price3, true, 0.01, 1000, getLocale(request));
        price4AsDouble = PropertyValidator.validateDouble(errors, "price4",
                price4, true, 0.01, 1000, getLocale(request));
        price5AsDouble = PropertyValidator.validateDouble(errors, "price5",
                price5, true, 0.01, 1000, getLocale(request));


        return errors;

    }

    private void reset() {
        idSeller = null;
        idCountry = null;
        price1 = null;
        price1AsDouble = 0;
        price2 = null;
        price2AsDouble = 0;
        price3 = null;
        price3AsDouble = 0;
        price4 = null;
        price4AsDouble = 0;
        price5 = null;
        price5AsDouble = 0;
        range1 = 2;
        range2 = 5;
        range3 = 10;
        range4 = 15;
        range5 = 20;        
    }
}
